module ecs {
    /**
     * RenderTarget2D的包装器，可以选择在屏幕尺寸更改时自动调整自身大小
     */
    export class RenderTexture {
        /**
         * 调整在调用onSceneBackBufferSizeChanged时应发生的大小调整行为
         */
        public ResizeBehavior: RenderTextureResizeBehavior = RenderTextureResizeBehavior.SizeToSceneRenderTarget;
        
        /**
         * 此RenderTexture管理的RenderTarget2D
         */
        public RenderTraget: egret.DisplayObject;
        /**
         * 适当时由渲染器自动调用。 让resizeBehavior生效，以便自动调整大小
         * @param newWidth 
         * @param newHeight 
         */
        public OnSceneBackBufferSizeChanged(newWidth: number, newHeight: number){
            switch (this.ResizeBehavior){
                case RenderTextureResizeBehavior.None:
                    break;
                case RenderTextureResizeBehavior.SizeToSceneRenderTarget:
                    this.Resize(newWidth, newHeight);
                    break;
                case RenderTextureResizeBehavior.SizeToScreen:
                    
                    break;
            }
        }

        /**
         * 将RenderTarget2D调整为指定大小
         * @param width 
         * @param height 
         */
        public Resize(width: number, height: number){
            if (this.RenderTraget.width == width && this.RenderTraget.height == height)
                return;

            this.Dispose();

            //TODO: renderTarget = create();
        }

        public Dispose(){
            if (this.RenderTraget != null){
                this.RenderTraget = null;
            }
        }
    }

    /**
     * 处理onSceneBackBufferSizeChanged时应该发生的情况。 
     * 默认为SizeToSceneRenderTarget
     */
    enum RenderTextureResizeBehavior {
        None,
        SizeToSceneRenderTarget,
        SizeToScreen
    }
}